package com.zelin.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.annotation.HandlesTypes;

/**
 * ------------------------------
 * 功能：
 * 作者：WF
 * 微信：hbxfwf13590332912
 * 创建时间：2021/11/15-10:40
 * ------------------------------
 */
@ControllerAdvice
public class MyHandlerException {

    @ExceptionHandler(MyException.class)
    public String error(MyException e, Model model){
        //1. 定义异常信息
        String msg = "出现了未知异常！";
        //2. 判断e对象是否有值
        if(e != null){
            msg = e.getMessage();
        }
        //3. 将错误信息放到model
        model.addAttribute("msg",msg);
        //4. 到达错误页面显示异常！
        return "error";
    }
}
